﻿using System.Runtime.InteropServices;
using System.Text;
using System.IO;

namespace HurricanePackage
{
    public class ConfigIni
    {
        public string m_path; //ini文件的路径
        public ConfigIni(string _path)
        {
            this.m_path = _path;
        }
        [DllImport("kernel32")]
        public static extern long WritePrivateProfileString(string section, string key, string value, string path);
        [DllImport("kernel32")]
        public static extern int GetPrivateProfileString(string section, string key, string deval, StringBuilder stringBuilder, int size, string path);

        //写入ini文件
        public void WriteIniContent(string _section, string _key, string _value)
        {
            WritePrivateProfileString(_section, _key, _value, this.m_path);
        }
        //读取ini文件
        public string ReadIniContent(string _section, string _key)
        {
            StringBuilder temp = new StringBuilder(255);
            int i = GetPrivateProfileString(_section, _key, "", temp, 255, this.m_path);
            return temp.ToString();
        }
        //判断路径是否正确
        public bool IsIniPath()
        {
            return File.Exists(this.m_path);

        }
    }
}
